/**
 *@info 卡盟公共方法
**/

export default function () {
  /**
     *@describe 错误气泡
     *@param {Object} (data) 显示数据
     *@param {Object} (postData) 请求参数
    **/
  Vue.prototype.errorBubble = function (data = '', postData) {//错误处理
    const _self = this;

    const layerConfirm = function (options, cb) {
      let layerIndex = layer.open({
        title: options.title || '提示',
        content: options.content,
        btn: options.btn || ['确定'],
        shadeClose: false,
        yes () {
          layer.close(layerIndex);
          if (typeof cb == 'function') {
            cb()
          }
        }
      });
    }

    if (data.code == "671") {
      Jsborya.dialog({
        content: "登录已过期，请重新登录",
        btn: ['确定'],
        code: '671',
        yes: function () {
          console.log(1);
        }
      });
    } else if (data.code == "2000") { // 版本升级弹窗
      Jsborya.updateVersion(data.data);
    } else if (data.code == "687" || data.code == "689") { // 687没有营运商权限；689有营运商权限，没有区域权限
      var tips = '', unicomTips = '', cardTypeT = '',
        merchantAttribute = data.data.merchantAttribute,
        cardType = data.data.cardType, // 卡号类型1，远特2，联通3，移动4，电信
        scopeId = data.data.scopeId, // 开卡地区编码
        areaName = data.data.areaName, // 开卡地区名称
        attributeStatus = data.data.attributeStatus, // 0,无1,申请中
        isMain = data.data.isMain, // 是否是主账号
        className = ''; // 拼接图标
      if (data.code == 687) {
        areaName = '';
      }
      if (cardType == 2) {
        cardTypeT = "联通"
        className = 'layer-icon-un'
      } else if (cardType == 1) {
        cardTypeT = "远特"
        className = 'layer-icon-yt'
      } else if (cardType == 3) {
        cardTypeT = "移动"
      } else if (cardType == 4) {
        cardTypeT = "电信"
      }

      if (attributeStatus == 0) {
        if (cardType != 1) {
          unicomTips = `<p class="red f-fs-12 f-mt-5">注：目前仅接受卡盟已合作${cardTypeT}业务的地市商户申请售卖，其他地市商户即将开放申请，敬请期待！</p>`;
        } else {
          unicomTips = ''
        }
        if (isMain == 1) {
          tips = `您当前没有开通售卖${cardTypeT}${areaName}的号卡<br>是否要申请售卖？`;

          layerConfirm({
            content: `<p class="layer-icon-wenhao"></p><p class="f-tac">${tips}</p>${unicomTips}`,
            btn: ['确定', '取消']
          },
            function () {
              if (data.code == 687) { // 跳转到售卡权限申请界面
                Jsborya.pageJump({
                  url: "",
                  stepCode: "2005",
                  depiction: "售卡申请",
                  data: {
                    merchantAttribute: merchantAttribute,
                    cardType: cardType,
                    scopeId: scopeId
                  }
                })
              } else if (data.code == 689) { // 直接申请开通区域权限
                _self.AJAX('/ums/c/merchant/applyScope', {
                  params: {
                    type: cardType,
                    scopeId: scopeId
                  },
                  userInfo: postData.userInfo
                }, function (resdata) {
                  if (resdata.code == 200) {
                    layerConfirm({
                      content: `<p class="${className}"></p><p class="f-tac f-fs-16">增加${cardTypeT}${areaName}的申请已受理<br>请耐心等待审核结果</p>`
                    })
                  }
                }, false, true)
              }
            })
        } else {
          layerConfirm({
            content: `<p class="layer-icon-wenhao"></p><p class="f-tac f-fs-16">您当前没有开通售卖${cardTypeT}${areaName}的号卡<br>请商户管理员发起申请</p>${unicomTips}`,
            btn: ['确定', '取消']
          })
        }
      } else if (attributeStatus == 1) {
        if (data.code == "687") {
          layerConfirm({
            content: `<p class="${className}"></p><p class="f-tac f-fs-16">您的${cardTypeT}售卡权限申请已受理<br>请耐心等待审核结果</p>`
          })
        } else if (data.code == "689") {
          layerConfirm({
            content: `<p class="${className}"></p><p class="f-tac f-fs-16">增加${cardTypeT}${areaName}合作的申请已受理<br>请耐心等待审核结果</p>`
          });
        }
      }
    } else if (data.code == "678") {
      layerConfirm({
        content: '订单超时已关闭',
        btn: ['返回首页', '取消'],
      }, () => {
        Jsborya.pageJump({
          url: `../../${APP_SOURCE.appId}/index.html`,
          depiction: "",
          stepCode: '2001'
        })
      })
    } else if (data.code == "649") {//激活提示
      Jsborya.dialog({
        content: "",
        btn: [],
        code: '649'
      });
    } else if (data.code == "653") {//商户激活提示
      Jsborya.dialog({
        content: "",
        btn: [],
        code: '653'
      });
    } else if (data.code == "724") {//打开GPS
      Jsborya.dialog({
        content: "当前定位功能未打开，请打开定位",
        btn: ["打开定位", "取消"],
        code: "724"
      });
    } else if (data.code == "725") {//GPS异常
      Jsborya.dialog({
        content: "当前位置信息不可用，请重新获取。",
        btn: ["重新获取", "取消"],
        code: '725'
      });
    } else if (data.code == "654") {
      layerConfirm({
        content: '尊敬的用户，当前套餐月底不允许开卡，请更换套餐。'
      })
    } else if (data.code == "695") {
      layerConfirm({
        content: '<div class="f-tal" style="line-height: 1.65;">尊敬的合作伙伴：<p style="text-indent:20px;margin:3px 0;">根据《电话用户实名制身份证信息入网规定》，所有制成卡、制白卡号码，需要上传预留机主身份证信息。历史已制卡成功未激活号码，需由制卡商户补充上传预留机主身份证信息后，方可激活。</p><p style="text-indent:20px;margin:3px 0;">需由制卡商户由“制卡补录”功能上传</p></div>'
      })
    } else {
      layer.open({
        content: data.msg || data,
        skin: "msg",
        time: 3
      });
    }
  };
}
